package com.hspedu.newData.dmsxl.树.构造二叉树;

import com.hspedu.newData.dmsxl.ds.TreeNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-12 
 * @Version: 1.0
 */

// todo 递归太重要了
public class LC108将有序数组转换为二叉搜索树 {

    public TreeNode sortedArrayToBST(int[] nums) {

        return findNode(nums,0,nums.length);
    }

    public TreeNode findNode(int[] nums,int begin,int end){
        if(begin >= end){
            return null;
        }

        int mid = begin + (end - begin) / 2;

        TreeNode root = new TreeNode(nums[mid]);

        root.left = findNode(nums,begin,mid);
        root.right = findNode(nums,mid+1,end);

        return root;
    }

}
